//
//  UserLoginPack.swift
//  GeneralNetworkTool
//
//  Created by Jin on 2018/5/23.
//  Copyright © 2018年 Jin. All rights reserved.
//

import Foundation

struct UserLoginRequestData:Codable {
    
    let loginId:String
    let loginPasswd:String
    
    enum CodingKeys:String,CodingKey {
        case loginId
        case loginPasswd
    }
    
    func encode(to encoder:Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(loginId, forKey: .loginId)
        try container.encode(loginPasswd, forKey: .loginPasswd)
    }
    
    init(loginId:String,loginPasswd:String) {
        self.loginId = loginId
        self.loginPasswd = loginPasswd
    }
}


class UserLoginRequest:BaseRequest {
    
    var requestData:UserLoginRequestData?
    var sign:String?
    
    enum CodingKeys:String,CodingKey {
        case requestData
        case sign
    }
    
    override func encode(to encoder:Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encodeIfPresent(requestData, forKey: .requestData)
        
        let data = try? JSONEncoder().encode(requestData)
        let signMD5 = signFromRequestParam(requestParam: requestParam!, data: data!)
        try container.encodeIfPresent(signMD5, forKey: .sign)
        try super.encode(to: container.superEncoder())
    }
}


struct UserLoginResponseDataItem:Codable {
    
    let IDENTITY_NUM:String
    let BRANCHID:String
    let STATUS:String
    let REAL_NAME:String
    let CERT_NO:String
    let MOBILE:String
    
    init(from decoder:Decoder) throws {
        let container = try decoder.container(keyedBy: UserLoginResponseDataItem.CodingKeys.self)
        let IDENTITY_NUM = try container.decode(String.self, forKey: .IDENTITY_NUM)
        let BRANCHID = try container.decode(String.self, forKey: .BRANCHID)
        let STATUS = try container.decode(String.self, forKey: .STATUS)
        let REAL_NAME = try container.decode(String.self, forKey: .REAL_NAME)
        let CERT_NO = try container.decode(String.self, forKey: .CERT_NO)
        let MOBILE = try container.decode(String.self, forKey: .MOBILE)
        
        self.init(IDENTITY_NUM: IDENTITY_NUM, BRANCHID: BRANCHID, STATUS: STATUS, REAL_NAME: REAL_NAME, CERT_NO: CERT_NO, MOBILE: MOBILE)
    }
    
    init(IDENTITY_NUM:String,
         BRANCHID:String,
         STATUS:String,
         REAL_NAME:String,
         CERT_NO:String,
         MOBILE:String)
    {
        self.IDENTITY_NUM = IDENTITY_NUM
        self.BRANCHID = BRANCHID
        self.STATUS = STATUS
        self.REAL_NAME = REAL_NAME
        self.CERT_NO = CERT_NO
        self.MOBILE = MOBILE
    }
}

struct UserLoginResponse:Codable {
    let emp_list:[String]
    let Result:String
    let ErrMsg:String
    
    init(from decoder:Decoder) throws {
        let container = try decoder.container(keyedBy: UserLoginResponse.CodingKeys.self)
        let emp_list = try container.decode([String].self, forKey: .emp_list)
        let Result = try container.decode(String.self, forKey: .Result)
        let ErrMsg = try container.decode(String.self, forKey: .ErrMsg)
        
        self.init(emp_list: emp_list, Result: Result, ErrMsg: ErrMsg)
    }
    
    init(emp_list:[String],
         Result:String,
         ErrMsg:String)
    {
        self.emp_list = emp_list
        self.Result = Result
        self.ErrMsg = ErrMsg
    }
}













